<?php

namespace App\Models\Article\Category;

use App\Models\Article\ArticleCategoryModel;
use App\Models\BaseModel;
use App\Models\Traits\KfSoftDeletes;
use Illuminate\Database\Eloquent\Relations\HasOne;

class ArticleCategoryOperateResultModel extends BaseModel
{
    use KfSoftDeletes;

    protected $table = "article_category_operate_result";

    protected $fillable = [
        "targetId",
        "operateType",
        "status",
        "createdAt",
        "createdByUid",
        "updatedAt",
        "updatedByUid"
    ];

    const OPERATE_TYPE_SHOW     = 1;
    const OPERATE_TYPE_READ     = 2;
    const OPERATE_TYPE_FORWARD  = 3;
    const OPERATE_TYPE_COLLECT  = 4;
    const OPERATE_TYPE_SUPPORT  = 5;
    const OPERATE_TYPE_CATEGORY = 6;

    const OPERATE_TYPE_TEXT = [
        self::OPERATE_TYPE_SHOW    => "展示数",
        self::OPERATE_TYPE_READ    => "阅读数",
        self::OPERATE_TYPE_FORWARD => "转发数",
        self::OPERATE_TYPE_COLLECT => "收藏数",
        self::OPERATE_TYPE_SUPPORT => "点赞数",
    ];

    const SAVE_RESULT_TYPE = [
        self::OPERATE_TYPE_COLLECT,
        self::OPERATE_TYPE_SUPPORT
    ];

    const OPERATE_TYPE_PREFIX = [
        self::OPERATE_TYPE_SHOW    => "show",
        self::OPERATE_TYPE_READ    => "read",
        self::OPERATE_TYPE_FORWARD => "forward",
        self::OPERATE_TYPE_COLLECT => "collect",
        self::OPERATE_TYPE_SUPPORT => "support"

    ];

    const ALL_OPERATE_TYPE_PREFIX = [
        self::OPERATE_TYPE_SHOW     => "show",
        self::OPERATE_TYPE_READ     => "read",
        self::OPERATE_TYPE_FORWARD  => "forward",
        self::OPERATE_TYPE_COLLECT  => "collect",
        self::OPERATE_TYPE_SUPPORT  => "support",
        self::OPERATE_TYPE_CATEGORY => "category"
    ];

    const STATUS_SUCCESS = 1;
    const STATUS_CANCEL  = 0;
    const STATUS_TEXT    = [
        self::STATUS_SUCCESS => "成功",
        self::STATUS_CANCEL  => "取消",
    ];

    /**
     * @return HasOne
     */
    public function categoryRel(): HasOne
    {
        return $this->hasOne(ArticleCategoryModel::class, "id", "targetId");
    }
}
